package db_main

import (
	"fmt"
	"longmen/server/config/global"
	"longmen/server/pkg/common/helper/util"
	"longmen/server/pkg/db/mysql"
	"longmen/server/pkg/db/mysql/models/models_main"
)

func GetUserWithdrawAccountsParam(param map[string]interface{}) ([]*models_main.UserWithdrawAccount, error) {
	fName := "GetUserWithdrawAccountsParam"
	o := make([]*models_main.UserWithdrawAccount, 0)
	table := mysql.GetRTable(&models_main.UserWithdrawAccount{})
	mysql.Condition(table, param, "", "", 0, 0)
	err := table.Find(&o).Error
	if err != nil {
		err = fmt.Errorf("%s%s", util.Convert(fName), err.Error())
	}
	return o, err
}

func GetUserWithdrawAccountParam(param map[string]interface{}) (*models_main.UserWithdrawAccount, error) {
	fName := "GetUserWithdrawAccountParam"
	o := &models_main.UserWithdrawAccount{}
	table := mysql.GetRTable(&models_main.UserWithdrawAccount{})
	mysql.Condition(table, param, "", "", 0, 0)
	err := table.Find(o).Error
	if err != nil {
		err = fmt.Errorf("%s%s", util.Convert(fName), err.Error())
	}
	return o, err
}

func UpdateUserWithdrawAccount(columns []string, account *models_main.UserWithdrawAccount) error {
	fName := "UpdateUserWithdrawAccount"
	err := global.GetX().Where("id = ?", account.Id).Select(columns).Updates(account).Error
	if err != nil {
		return fmt.Errorf("%s%s", util.Convert(fName), err.Error())
	}
	return nil
}

func InsertUserWithdrawAccount(account *models_main.UserWithdrawAccount) error {
	fName := "InsertUserWithdrawAccount"
	err := global.GetX().Create(account).Error
	if err != nil {
		return fmt.Errorf("%s%s", util.Convert(fName), err.Error())
	}
	return nil
}
